<?php

/***  DOCUMENTATION LAYER

Ceo Unit Testing

Last Update: Sep 2007
	
DESCRIPTION
	testing CEO with SimpleTest unit testing
	
NOTES
		
***/

// timer and buffer
$_tx0 = microtime();
ob_start();
$test_root = ( strpos(dirname(__FILE__), 'repository') === false ) ? '' : '../';

// load SimpleTest
require_once($test_root . 'simpletest/unit_tester.php');
require_once($test_root . 'simpletest/reporter.php');
require_once($test_root . 'simpletest.ceo_reporter.inc.php');
$debug = 1;

// class(es) to be tested
#global $Global;    // declare globals (tests in suite have local scope)
require_once($test_root . '../php_ceo/ext/input/element.class.php');
require_once($test_root . '../php_ceo/ext/input/input_text.class.php');

// load class (or in setUp below)  
$TestClass = new CeoFormElementInputText($name='test', $type='input_email', $label='test', $is_required=1, $maxlength, $minlength);


// Unit Test Object
class Sample extends UnitTestCase 
{
  function setUp()
  {
    global $TestClass;
    $this->TestClass = $TestClass;

  }
  
  function tearDown() 
  {
  }

  function testIsValid()
  {
    $this->TestClass->_value = 'klenwell@gmail.com';
    $this->assertTrue( $this->TestClass->is_valid() );
  }
  
  function testIsInvalid()
  {
    $this->TestClass->_value = 'klenwell';
    $this->assertFalse( $this->TestClass->is_valid() );
    print "<p>prompt: {$this->TestClass->_prompt}</p>";
  }
  
  function testTooLong()
  {
    $this->TestClass->_value = 'dfkjasdflfgsdfgsdfgfsdgsdfgsdgfgafasfdafgasfgfhsdgadsfasffgfdhgAFFDSFGRTafdsfghsdgdfgaffdghfgafsdfavnbhnuykgvstbhavghbjagvafrgifmoighpkcpmdfjopdifjasfmoaifjognofvnklasfnoigjoigimaofnosiagnoidgnosgnodf@example.com';
    $this->assertFalse( $this->TestClass->is_valid() );
    print "strlen :".strlen($this->TestClass->_value)."</p>";
    print "<p>prompt: {$this->TestClass->_prompt}</p>";
  }
  
  function testTooShort()
  {
    $this->TestClass->_value = '';
    $this->assertFalse( $this->TestClass->is_valid() );
    print "<p>prompt: {$this->TestClass->_prompt}</p>";
  }
}

// run test
$UnitTest = &new Sample();
$UnitTest->run(new CeoReporter());


// debug
if ( $debug ) print '<pre>' . print_r($UnitTest, 1) . '</pre>';

// timer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4);
print "<h6 style='margin:12px 0 4px;'>test '{$UnitTest->_label}' complete in $stx s</h6>";
print "<h6 style='margin:4px 0;'>more info on SimpleTest available at <a href='http://simpletest.org/'>http://simpletest.org/</a></h6>";
    
// dump buffer
while (ob_get_level() > 0) { ob_end_flush(); } flush();
?>
